<?php


namespace App\Lib;


class DataFormart
{
    /**
     * 公共的list转dictionary数组方法
     * @param $data
     * @param string $key
     * @return array
     */
    public static function dataToDic($data, $key = "id"):array
    {
        $dic = [];
        foreach($data as $info){
            $dic[$info[$key]] = $info;
        }
        return $dic;
    }

    public static function dataToGroup($data,$key = "id"):array
    {
        $dic = [];
        foreach($data as $info){
            if(!isset($dic[$info[$key]])){
                $dic[$info[$key]] = [];
            }
            $dic[$info[$key]][] = $info;
        }
        return $dic;
    }
}